import docker
import agentic_system

import json
import uuid
from swebench.harness.run_evaluation import run_instance
from swebench.harness.test_spec.test_spec import make_test_spec, TestSpec

def compute_score(data_source, solution_str, ground_truth, extra_info):
    breakpoint()
    instance = json.loads(data_source[0])
    lines=solution_str.lstrip().splitlines()
    instance_id = str(uuid.uuid4())
    pred= {"model_name_or_path":"fake_model","model_patch":"\n".join(lines[1:]),"instance_id":instance_id}
    test_spec = make_test_spec(instance=instance,namespace="swebench", instance_image_tag="latest")
    res = run_instance(test_spec=test_spec,pred=pred,rm_image=False,force_rebuild=False,client=docker.from_env(),run_id=instance_id,timeout=3000,rewrite_reports=False)
    if res:
        instance_id, report = res
        print("\n\n"*3)
        print("wangmin")
        print(instance_id)
        print(report)
        print("\n\n"*3)
        # return 20 if report[instance_id]["resolved"] else 0
        return 20
    else:
        return 0